Generate an ESXi Host CPU and Memory Utilization Report using PowerCLI

Native vCenter reporting is clunky. It gives you graphs and raw data dumps, but it will not hand you a perfectly formatted, easily readable spreadsheet without manual effort or expensive add-ons. If you want a clean report of your cluster's CPU and Memory utilization, you must automate it with PowerCLI.

Here is how to extract exact capacity and utilization percentages for every host in your cluster.

The Script

This script calculates the CPU and Memory usage percentages for the hosts in a target cluster and exports the clean data directly to a CSV file.

# Connect to your vCenter Server
Connect-VIServer -Server "YOUR_VCENTER_IP_OR_FQDN"

$ClusterName = "YOUR_CLUSTER_NAME"
$Hosts = Get-Cluster -Name $ClusterName | Get-VMHost
$Report = @()

foreach ($VMHost in $Hosts) {
    $CpuUsagePct = [math]::Round(($VMHost.CpuUsageMhz / $VMHost.CpuTotalMhz) * 100, 2)
    $MemUsagePct = [math]::Round(($VMHost.MemoryUsageGB / $VMHost.MemoryTotalGB) * 100, 2)

    $Report += [PSCustomObject]@{
        HostName         = $VMHost.Name
        Cluster          = $ClusterName
        CpuTotalMHz      = $VMHost.CpuTotalMhz
        CpuUsageMHz      = $VMHost.CpuUsageMhz
        CpuUsagePercent  = "$CpuUsagePct %"
        MemTotalGB       = [math]::Round($VMHost.MemoryTotalGB, 2)
        MemUsageGB       = [math]::Round($VMHost.MemoryUsageGB, 2)
        MemUsagePercent  = "$MemUsagePct %"
    }
}

$Report | Export-Csv -Path "C:\Host_Utilization_Report.csv" -NoTypeInformation
Disconnect-VIServer -Confirm:$false

Key Technical Details

  • Calculated Metrics: It translates raw MHz and GB into a readable percentage using native math functions to round to two decimal places.
  • Prerequisites: You must have the VMware.PowerCLI module installed and be able to authenticate to the vCenter server.
  • Execution: Simply replace the vCenter and Cluster variables with your actual environment names.